package com.zlm.mapper;

import com.zlm.pojo.Emp;
import org.apache.ibatis.annotations.*;

/**
 * @author 13026
 */
@Mapper
public interface EmpMapper {
    // 根据ID删除数据
    // 返回值影响了几条数据
    // #{id}生成预编译sql，防止sql注入
    // ${id}拼接sql，有sql注入风险
    @Delete("delete from db01.emp where id = #{id}")
    public int delete(Integer id);

    // 新增员工
    // 返回主键，封装到emp对象的id属性
    @Options(keyProperty = "id", useGeneratedKeys = true)
    @Insert("insert into db01.emp (username, name, gender, image, job, entrydate, dept_id, create_time, update_time) VALUE (#{username},#{name},#{gender},#{image},#{job},#{entrydate},#{deptId},#{createTime},#{updateTime})")
    public void insert(Emp emp);

    // 更新员工
    @Update("update db01.emp set password = #{password}, update_time = #{updateTime} where id = #{id}")
    public void update(Emp emp);

    // 查询员工
//    @Results({
//            @Result(column = "update_time", property = "updateTime"),
//    })
    @Select("select * from db01.emp where id = #{id}")
    public Emp selectById(Integer id);
}
